<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<h1></h1>
<audio id="el-audio"></audio>
<button id="el-start">开始录音</button>
<button id="el-stop">提交录音</button>
<button id="el-blob">blob</button>

<script src="/assets/js/jquery.min.js"></script>
<script src="/resource/js/ajax.js"></script>
<script>

    elAudio = document.getElementById("el-audio");

    var errfn = function (err) {
        console.log(err);
    }

    window.URL = window.URL || window.webkitURL;
    navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;

    navigator.getUserMedia( { "audio":true }, function (stream) {
        elAudio.src = window.URL.createObjectURL(stream);
//        elAudio.play();
    }, errfn );

    document.getElementById("el-start").addEventListener("click", function () {
        elAudio.play();
    }, false);

    document.getElementById("el-stop").addEventListener("click", function () {
        elAudio.pause();
        console.log( elAudio.src );
//        var blobfile = new Blob(window.URL.revokeObjectURL(elAudio.src));
//        var bf = blobfile.getBlob("test.wav");
        var a = document.createElement("a");
        //a.href = window.URL.createObjectURL(bf);
        a.href = elAudio.src;
        a.download = "test.wav";
        a.textContent = "录";
        document.body.appendChild(a);

        rc_ajax.post("audio", {"src":elAudio.src }, function (resp) {
           console.log(resp);
        });
    }, false);
    
    document.getElementById("el-blob").addEventListener("click", function () {
        var blob = new Blob(['hello world!']);
        var a = document.createElement("a");
        a.href = window.URL.createObjectURL(blob);
        a.download = "hello-world.txt";
        a.textContent = "Download Hello World";
        document.body.appendChild(a);
    }, false);
</script>

</body>
</html>